#============================================
#知识点
# import pymysql
# from pymysql import cursors
# sql_obj = pymysql.connect(host="127.0.0.1",port = 3306,user="root",passwd="369369",charset="utf8")
# cursor = sql_obj.cursor(cursors.DictCursor)  #产生一个游标对象 执行命令   cursors.DictCursor 以字典形式表示
# cursor.execute("use hs")
# cursor.execute("select * from emp1")

# #注意：读取文件，类似光标的移动
# print(cursor.fetchmany(2))           #指定拿几个
# cursor.scroll(0,"relative")       #从当前位置往右移动几位
# print("=====================")
# print(cursor.fetchone())            #拿一个
# cursor.scroll(0,"absolute")        #从起始位置往右移动几位
# print("=====================")
# print(cursor.fetchall())            #拿所有
#============================================
#补充 
# 1、针对增删改pymysql需要二次确认才能真正的操作数据 autocommit = True
# 2、增加多个用到cursor.executemany(sql语句,[(),(),()])  元组列表
import pymysql
from pymysql import cursors
conn = pymysql.connect(host="127.0.0.1",port=3306,user="root",passwd="369369",db="hs",charset="utf8",autocommit=True)
use_obj = conn.cursor(cursors.DictCursor)
#增
# sql = "insert into user(name,password,maker_id) values(%s,%s,%s)"
# # row = use_obj.execute(sql,("fbh","123",3))
# row = use_obj.executemany(sql,[("qwqd","123",2),("qwqqwd","123",2),("qqwqwqd","123",2)])
# print(row)
#改
# sql = "update user set name = %s where maker_id = 2"
# row = use_obj.execute(sql,("oooo"))
# print(row)
#删
# sql = "delete from user where id >= 10"
# row = use_obj.execute(sql)
# print(row)
#查
# sql = "select  * from user where id >=2"
# row = use_obj.execute(sql)
# print(row)
# dic = use_obj.fetchall()
# for i in dic:
#     print(i)

# try:
#     cursor = conn.cursor()
#     result = cursor.execute("delete from stu where sid = 12")
#     print(result)  # result是该sql会影响多少条数据
#     conn.commit()  # 提交
# except:
#     conn.rollback()  # 回滚
#============================================